﻿namespace BruteForce.Utilities
{
    public class MonitoredProperty<T>
    {
        private int _lastKnowedChangedLoopIndex;
        private T _property;

        public MonitoredProperty(T property)
        {
            _property = property;
            _lastKnowedChangedLoopIndex = BFGame.LoopIndex;
        }

        public T Property
        {
            get { return _property; }
            set
            {
                _lastKnowedChangedLoopIndex = BFGame.LoopIndex;
                _property = value;
            }
        }


        public int ChangedIn()
        {
            return _lastKnowedChangedLoopIndex;
        }

        public bool IsChangedSince(int loopIndex)
        {
            if (_lastKnowedChangedLoopIndex == 0) return false;
            return (_lastKnowedChangedLoopIndex == loopIndex);
        }
    }
}